<!DOCTYPE html>
<html>
	<head>
		<meta charset="utf-8">
		<title></title>
		<script src="../vue.js"></script>
		<script src="https://unpkg.com/vue-router@4"></script>
		<style>
		   ._active{
		      background-color : red;
		   }
		</style>
	</head>
	<body>
		<div id="app">
		  <h1>Hello App!</h1>
		  <p>
		    <!--使用 router-link 组件进行导航 -->
		    <!--通过传递 `to` 来指定链接 -->
		    <!--`<router-link>` 将呈现一个带有正确 `href` 属性的 `<a>` 标签-->
		    <router-link to="/" active-class = "_active">Home</router-link> |
		    <router-link to="/about" active-class = "_active">About</router-link> |
			<!-- 字符串 -->
			<router-link :to="{name:'cate', params: { userId: 123 }}" active-class = "_active">Cate</router-link> |
			<!-- 使用 v-bind 的 JS 表达式 -->
			<router-link v-bind:to="'/dart'" active-class = "_active">Dart</router-link> |
			<!-- 同上 -->
			<router-link :to="{ path: '/eat' }" active-class = "_active">Eat</router-link> |
			<!-- 命名的路由 -->
			<router-link :to="{ name: 'full', params: { userId: 123 }}" active-class = "_active">Full</router-link> |
			<!-- 带查询参数，下面的结果为 /register?plan=private -->
			<router-link :to="{ path: '/get', query: { plan: 'private' }}" active-class = "_active">Get</router-link>
		  </p>
		  <!-- 路由出口 -->
		  <!-- 路由匹配到的组件将渲染在这里 -->
		  <router-view></router-view>
		</div>
		
		<script>
		// 1. 定义路由组件.
		// 也可以从其他文件导入
		const Home = { 
			template: '<div @mouseover = "mouseover">Home</div>',
			methods: {
			    // 1、进入元素
			    mouseover () {
			      console.log('mouseover')
			    },
			    // 2、进入元素
			    mouseenter () {
			      console.log('mouseenter')
			    },
			    // 3、移动
			    mousemove () {
			      console.log('mousemove')
			    },
			    // 4、离开元素
			    mouseout () {
			      console.log('mouseout')
			    },
			    // 5、离开元素
			    mouseleave () {
			      console.log('mouseleave')
			    },
			    // 6、鼠标在元素上 按下
			    mousedown () {
			      console.log('mousedown')
			    },
			    // 7、鼠标在元素上 抬起
			    mouseup () {
			      console.log('mouseup')
			    }
			}
			
		 }
		const About = { 
			template: '<div @click="btnTap">About</div>',
			methods: {
				btnTap(){
					//2.通过params配置的：
					console.log(this.$route.query);
				}
			}
		}
		const Cate = { 
			template: '<div @click="btnTap">Cate</div>',
			methods: {
				btnTap(){
					//2.通过params配置的：
					console.log(this.$route.params);
				}
			}
		}
		const Dart = { 
			template: '<div @click="btnTap">Dart</div>',
			methods: {
				btnTap(){
					console.log(this.$route.query);
					console.log(this.$route.params);
				}
			}
		}
		const Eat = { template: '<div>Eat</div>' }
		const Full = { 
			template: `<div @click="btnTap">Full</div>` ,
			methods: {
				btnTap(){
					//2.通过params配置的：
					console.log(this.$route.path);
					console.log(this.$route.params);
					//this.$router.push("/about");
					//this.$router.push("/about?test1=1&test2=xxx");
					this.$router.push({path: '/about',query:{test1:1,'test2':'xxx'}});
					//this.$router.push({name:'cate', params: { userId: 123 }});
					console.log("this.$route.path = ",this.$route.path);
					//this.$router.push({path: '/dart?url=' + this.$route.path});
					
				}
			}
		}
		const Get = { 
			template: '<div @click="btnTap">Get</div>',
			methods: {
				btnTap(){
					//2.通过params配置的：
					console.log(this.$route.query);
				}
			}
		}
		// 2. 定义一些路由
		// 每个路由都需要映射到一个组件。
		// 我们后面再讨论嵌套路由。
		const routes = [
		  { path: '/', component: Home },
		  { path: '/about', component: About },
		  { path: '/cate/:userId', name:'cate', component: Cate },
		  { path: '/dart', component: Dart },
		  { path: '/eat', component: Eat },
		  { name: 'full', path: '/full/:userId', component: Full },
		  { path: '/get', component: Get }
		]
		 
		// 3. 创建路由实例并传递 `routes` 配置
		// 你可以在这里输入更多的配置，但我们在这里
		// 暂时保持简单
		const router = VueRouter.createRouter({
		  // 4. 内部提供了 history 模式的实现。为了简单起见，我们在这里使用 hash 模式。
		  history: VueRouter.createWebHashHistory(),
		  routes, // `routes: routes` 的缩写
		})
		 
		// 5. 创建并挂载根实例
		const app = Vue.createApp({})
		//确保 _use_ 路由实例使
		//整个应用支持路由。
		app.use(router)
		 
		app.mount('#app')
		 
		// 现在，应用已经启动了！
		</script>
	</body>
</html>
